/**
 * Temperature Unit Tests
 * Tests convert and toUnit for each Unit Type
 */

package cmsc495.mach2.test.unit;

import cmsc495.mach2.unit.TemperatureUnit;
import junit.framework.TestCase;

/**
 * @author Michael Swann
 */
public class TemperatureUnitValidation extends TestCase {
	// Amount of Error Allowed
	public static final double				DELTA				= 0.001;

	private static final double				CELSIUS_VALUE		= 300;
	private static final double				KELVIN_VALUE		= 573.15;
	private static final double				FAHRENHEIT_VALUE	= 572;
	private static final double				RANKINE_VALUE		= 1031.67;

	private static final double				values[]			= { CELSIUS_VALUE, KELVIN_VALUE, FAHRENHEIT_VALUE, RANKINE_VALUE };
	private static final TemperatureUnit[]	temperatureUnits	= TemperatureUnit.values();

	public TemperatureUnitValidation() {
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.TemperatureUnit#convert(double, mach2convert.englishunit.TemperatureUnit)}
	 * .
	 */
	public final void testConvert() {
		for (int i = 0; i < temperatureUnits.length; i++) {
			for (int j = 0; j < temperatureUnits.length; j++) {
				double result = temperatureUnits[i].convert(values[j], temperatureUnits[j]);
				System.out.println("ASSERT: " + values[i] + " = " + result + " " + temperatureUnits[i] + ".convert(" + values[j] + ", " + temperatureUnits[j] + "))");
				assertEquals(values[i], result, DELTA);
			}
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.TemperatureUnit#toCelsius(double)}.
	 */
	public final void testToCelsius() {
		for (int i = 0; i < temperatureUnits.length; i++) {
			double result = temperatureUnits[i].toCelsius(values[i]);
			System.out.println("ASSERT: " + CELSIUS_VALUE + " = " + result + " " + temperatureUnits[i] + ".toCelsius(" + values[i] + ") ");
			assertEquals(CELSIUS_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.TemperatureUnit#toKelvin(double)}.
	 */
	public final void testToKelvin() {
		for (int i = 0; i < temperatureUnits.length; i++) {
			double result = temperatureUnits[i].toKelvin(values[i]);
			System.out.println("ASSERT: " + KELVIN_VALUE + " = " + result + " " + temperatureUnits[i] + ".toKelvin(" + values[i] + ") ");
			assertEquals(KELVIN_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.TemperatureUnit#toFahrenheit(double)}.
	 */
	public final void testToFahrenheit() {
		for (int i = 0; i < temperatureUnits.length; i++) {
			double result = temperatureUnits[i].toFahrenheit(values[i]);
			System.out.println("ASSERT: " + FAHRENHEIT_VALUE + " = " + result + " " + temperatureUnits[i] + ".toFahrenheit(" + values[i] + ") ");
			assertEquals(FAHRENHEIT_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.TemperatureUnit#toRankine(double)}.
	 */
	public final void testToRankine() {
		for (int i = 0; i < temperatureUnits.length; i++) {
			double result = temperatureUnits[i].toRankine(values[i]);
			System.out.println("ASSERT: " + RANKINE_VALUE + " = " + result + " " + temperatureUnits[i] + ".toRankine(" + values[i] + ") ");
			assertEquals(RANKINE_VALUE, result, DELTA);
		}
	}

}
